package com.ruoyi.zhoubao.controller;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zhoubao.domain.ReqZhoubao;
import com.ruoyi.zhoubao.service.IReqZhoubaoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * zhoubaoBaseController
 * 
 * @author ruoyi
 * @date 2025-10-16
 */
@Controller
@RequestMapping("/zhoubao/zhoubao_Base")
public class ReqZhoubaoController extends BaseController
{
    private String prefix = "zhoubao/zhoubao_Base";

    @Autowired
    private IReqZhoubaoService reqZhoubaoService;

    @RequiresPermissions("zhoubao:zhoubao_Base:view")
    @GetMapping()
    public String zhoubao_Base()
    {
        return prefix + "/zhoubao_Base";
    }

    /**
     * 查询zhoubaoBase列表
     */
    @RequiresPermissions("zhoubao:zhoubao_Base:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ReqZhoubao reqZhoubao)
    {
        startPage();
        List<ReqZhoubao> list = reqZhoubaoService.selectReqZhoubaoList(reqZhoubao);
        return getDataTable(list);
    }

    /**
     * 导出zhoubaoBase列表
     */
    @RequiresPermissions("zhoubao:zhoubao_Base:export")
    @Log(title = "zhoubaoBase", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ReqZhoubao reqZhoubao)
    {
        List<ReqZhoubao> list = reqZhoubaoService.selectReqZhoubaoList(reqZhoubao);
        ExcelUtil<ReqZhoubao> util = new ExcelUtil<ReqZhoubao>(ReqZhoubao.class);
        return util.exportExcel(list, "zhoubaoBase数据");
    }

    @Log(title = "周报基础数据", businessType = BusinessType.IMPORT)
    @RequiresPermissions("zhoubao:zhoubao_Base:import")
    @PostMapping("/importData")
    @ResponseBody
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<ReqZhoubao> util = new ExcelUtil<ReqZhoubao>(ReqZhoubao.class);
        List<ReqZhoubao> ReqZhoubaoList = util.importExcel(file.getInputStream());
        reqZhoubaoService.deleteReqZhoubaoByAll();
        String message = reqZhoubaoService.importReqZhoubao(ReqZhoubaoList, updateSupport, getLoginName());
        return AjaxResult.success(message);
    }




    /**
     * 新增zhoubaoBase
     */
    @RequiresPermissions("zhoubao:zhoubao_Base:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存zhoubaoBase
     */
    @RequiresPermissions("zhoubao:zhoubao_Base:add")
    @Log(title = "zhoubaoBase", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ReqZhoubao reqZhoubao)
    {
        String message = reqZhoubaoService.initZhoubao();
        return AjaxResult.success(message);
    }

    /**
     * 修改zhoubaoBase
     */
    @RequiresPermissions("zhoubao:zhoubao_Base:edit")
    @GetMapping("/edit/{需求单编号}")
    public String edit(@PathVariable("需求单编号") String 需求单编号, ModelMap mmap)
    {
        ReqZhoubao reqZhoubao = reqZhoubaoService.selectReqZhoubaoBy需求单编号(需求单编号);
        mmap.put("reqZhoubao", reqZhoubao);
        return prefix + "/edit";
    }

    /**
     * 修改保存zhoubaoBase
     */
    @RequiresPermissions("zhoubao:zhoubao_Base:edit")
    @Log(title = "zhoubaoBase", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ReqZhoubao reqZhoubao)
    {
        return toAjax(reqZhoubaoService.updateReqZhoubao(reqZhoubao));
    }

    /**
     * 删除zhoubaoBase
     */
    @RequiresPermissions("zhoubao:zhoubao_Base:remove")
    @Log(title = "zhoubaoBase", businessType = BusinessType.DELETE)
    @PostMapping( "/dodeal")
    @ResponseBody
    public AjaxResult remove(String ids)
    {

        String message = reqZhoubaoService.initZhoubao();
        return AjaxResult.success(message);
    }
}
